home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2903 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: VC++ v.4.0 conversion problems
  5. Date: Sat, 20 Jan 1996 00:29:08 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4dpcvt$5gs@news.halcyon.com>
  8. References: <4dls1n$ldp@eagle.novo.dk>
  9. NNTP-Posting-Host: blv-pm10-ip8.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. morb@novo.dk (Morten Brun) wrote:
  13.  
  14. >I am having a lot of problems when compiling under v.4. as I am etting
  15.  
  16. >a lot of conversions errors due to the new behavior of v.4 like:
  17. >
  18. >LPWSTR                    lpszName;
  19.  
  20. >GetPrivateProfileStringA("x", "y", "",lpszName, sizeof(lpszName),
  21. >\\xxx.INI");
  22.  
  23. >error c26664: cannot convert parm. 4 from unsigned short * to char *
  24. >or
  25. >error C2446: '=' : no conversion from 'char *' to 'unsigned char *'
  26. >error C2664: 'wcstombs' : cannot convert parameter 1 from 'unsigned
  27. >char [32]' error C2664: 'mbstowcs' : cannot convert parameter 2 from
  28. >'unsigned char *' to 'const char *'
  29. >error C2664: 'ctime' : cannot convert parameter 1 from 'unsigned long
  30. >*' to 'const long *'
  31. >----------------------------------------------------------------------------------------
  32. >...
  33.  
  34. >Regards Morten
  35.  
  36. The first case involves a UNICODE to ANSI conversion problem.
  37. The code declares lpszName to point to an array of wide-chars (2-byte
  38. UNICODE 'characters'), yet the ...A() version of the function
  39. explicitly invokes the ANSI version of the API (all APIs ending in A
  40. and taking strings assume ANSI strings).  Usually, you just call
  41. GetPrivateProfileString and macros automatically steer you to the W or
  42. A incarnations based on whether you've defined UNICODE in the compile.
  43.  
  44. Lookup things like TCHAR and _TEXT to see more.
  45.  
  46. The char to unsigned char problems simply say the sign bit will be
  47. interpreted differently.  You can type-cast your way around it if you
  48. have to.
  49.  
  50.     typedef unsigned char BYTE;    // made in some header
  51.     ...
  52.     BYTE  myByte = (BYTE) 'c';    // cast to make 'c' appear unsigned
  53.  
  54. It's best, however, to take your compiler's objections to heart; you
  55. might introduce bugs by mixing signed and unsigned.
  56.  
  57. The errors you cited involving const are also really signed/unsigned
  58. errors.  Passing a normal pointer to a function expecting a const
  59. pointer is perfectly legal; passing a const pointer to a function that
  60. accepts a normal pointer is an error because the function is saying "I
  61. could change the pointed to data" and you're saying "don't change what
  62. this pointer points to."
  63.  
  64. Does this help?
  65.                     --Norm
  66.  
  67.